<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><?php echo $page_title; ?></title>
        <link rel="stylesheet" href="<?php echo getCssUrl() . 'default.css' ?>"/>
        <link rel="stylesheet" href="<?php echo getAppCssUrl('admin') . 'admin.css' ?>"/>
        <script type="text/javascript" src="<?php echo getJsUrl() . 'jquery.js' ?>"></script>
    </head>
    <style>
    #users img { border: none; }
    </style>
    <body>
        <div id="menu">
            <?php for($i=0,$j=count($apps);$i<$j;$i++) { ?>
            <?php if($i) { echo "&nbsp;|&nbsp;"; } ?>
            <strong><a href="<?php echo getAppUrl('admin', 'control') . '/app/' . $apps[$i]['name']; ?>"><?php echo ucwords($apps[$i]['name']); ?></a></strong>
            <?php } ?>
            <strong><a style="float: right; color: #f00;" href="<?php echo getAppUrl('admin', 'logout'); ?>">Sign Out</a></strong>
        </div>
        <div id="content">
            <form action="<?php echo getAppUrl('admin', 'control') . '/app/user/act/conf'; ?>" method="post">
                <table border="0" cellpadding="5" cellspacing="0">
                    <caption>User Configuration</caption>
                    <thead>
                        <tr>
                            <th><span>name</span></th>
                            <th><span>value</span></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                            foreach($config as $name => $value) {
                        ?>
                        <tr>
                            <td><?php echo ucwords(str_replace('_', ' ', $name)); ?></td>
                            <td>
                                <?php if($name=='email_validation') { ?>
                                <select name="<?php echo $name; ?>">
                                    <option value="0"<?php echo($value==0?' selected="selected"':''); ?>>No</option>
                                    <option value="1"<?php echo($value==1?' selected="selected"':''); ?>>Yes</option>
                                </select>
                                <?php continue; } ?>
                                <input name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
                            </td>
                        </tr>
                        <?php } ?>
                        <tr>
                            <td class="submit_td" colspan="2">
                                <input type="submit" name="submit_config" value="save"/>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </form>
            <table id="users" border="0" cellpadding="5" cellspacing="0">
                <caption>Users</caption>
                <tr>
                    <th>username</th>
                    <th>full name</th>
                    <th>active</th>
                    <th>verified</th>
                    <th>id card</th>
                </tr>
                <tbody>
                    <?php foreach($users as $user): ?>
                    <tr>
                        <td><?php echo $user['username']; ?></td>
                        <td><?php echo $user['name']; ?></td>
                        <td align="center"><input type="checkbox" name="active_user" id="active_user_<?php echo $user['user_id']; ?>" value="1"<?php echo($user['active']?' checked="true"':''); ?>/></td>
                        <td align="center"><input type="checkbox" name="verified_user" id="verified_user_<?php echo $user['user_id']; ?>" value="1"<?php echo($user['verified']?' checked="true"':''); ?>/></td>
                        <td><a href="#"><img height="100" src="<?php echo getAppImgUrl('admin') . 'user/idcard/' . $user['user_id'] . '.jpg'; ?>" alt="no id card" title="<?php echo $user['username']; ?>"/></a></td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
            <script type="text/javascript">
                (function($){
                    $(function(){
                        $("#users input[type='checkbox']").click(function(e){
                            var name = $(e.target).attr("name");
                            var id = $(e.target).attr("id").toString().replace(name+"_", "");
                            var checked = $(e.target).attr("checked")?1:0;
                            var url = window.location.toString() + "/act/edit";

                            $.post(url, {"name":name, "id":id, "checked":checked}, function(a){if(a){alert(a);}});
                        });

                        $("#users a").click(function(e){
                            e.preventDefault();
                            e.stopPropagation();

                            var kid = $(this).children(":first");
                            var url = $(kid).attr("src");
                            var title = $(kid).attr("title");

                            window.open(url, title);
                        });
                    });
                })(jQuery);
            </script>
        </div>
    </body>
</html>
